package net.learn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysJudgeQuery;
import net.learn.system.query.SysNewQuery;
import net.learn.system.service.SysJudgeService;
import net.learn.system.service.SysNewService;
import net.learn.system.vo.SysCheckBoxVO;
import net.learn.system.vo.SysJudgeVO;
import net.learn.system.vo.SysNewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 判断管理
 */
@RestController
@RequestMapping("sys/judge")
@Tag(name="判断管理")
@AllArgsConstructor
public class SysJudgeController {
    @Autowired
    private final SysJudgeService judgeService;

    @GetMapping("getJudge")
    @Operation(summary = "分页获取判断题列表")
    public Result<PageResult<SysJudgeVO>> getJudge(@Valid SysJudgeQuery query){
        PageResult<SysJudgeVO> page = judgeService.qryJudgeListPage(query);

        return Result.ok(page);
    }
    @PostMapping("getJudgeList")
    @Operation(summary = "获取判断列表")
    public Result<List<SysJudgeVO>> getJudgeList(@RequestBody SysJudgeQuery query){
        List<SysJudgeVO> list = judgeService.qryJudgeList();

        return Result.ok(list);
    }
    @PostMapping("getJudgePaper")
    @Operation(summary = "获取试卷判断列表")
    public Result<List<SysJudgeVO>> getJudgePaper(@RequestBody SysJudgeQuery query){
        List<SysJudgeVO> list = judgeService.qryJudgePaper(query);

        return Result.ok(list);
    }
    @PostMapping("getJudgePaperList")
    @Operation(summary = "获取正在考试试卷判断列表")
    public Result<List<SysJudgeVO>> getJudgePaperList(@RequestBody SysJudgeQuery query){
        List<SysJudgeVO> list = judgeService.qryJudgePaperList(query);

        return Result.ok(list);
    }
    @PostMapping("getJudgeRandList")
    @Operation(summary = "获取随机判断题")
    public Result<List<SysJudgeVO>> getJudgeRandList(@RequestBody SysJudgeQuery query){
        List<SysJudgeVO> list = judgeService.qryJudgeRandList(query);

        return Result.ok(list);
    }
    @PostMapping("/updateJudge")
    @Operation(summary = "修改判断")
    public Result<String> updateJudge(@RequestBody @Valid SysJudgeVO vo){
        judgeService.updateJudge(vo);

        return Result.ok();
    }
    @PostMapping("save")
    @Operation(summary = "新增判断")
    public Result<String> save(@RequestBody SysJudgeVO vo){
        judgeService.addJudge(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    public Result<String> deleteById(@RequestBody List<Long> idList){

        judgeService.delete(idList);
        return Result.ok();
    }
}

